package com.Tread;

import com.Tread.pool.dynamic.SinglePool;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.function.Supplier;

public class ComplatureTest {
    public static void main(String[] args) {
//        ThreadPoolExecutor threadPool = SinglePool.INSTANCE.getThreadPoolExecutor();
//        long time = System.currentTimeMillis();
////        int a = callA(1000);
////        int b = callB(1000);
////        int c = callC(1000);
//
//
//        CompletableFuture<Object> objectCompletableFuture = CompletableFuture.supplyAsync(() -> callA(1000), threadPool);
//
//        CompletableFuture<Object> objectCompletableFuture2 = CompletableFuture.supplyAsync(() -> callB(1000), threadPool);
//        CompletableFuture<Object> objectCompletableFuturec = CompletableFuture.supplyAsync(() -> callC(1000), threadPool);
//
//        CompletableFuture<Void> voidCompletableFuture = CompletableFuture.allOf(objectCompletableFuture, objectCompletableFuturec, objectCompletableFuture2);
//        voidCompletableFuture.join();
//
//        long time2 = System.currentTimeMillis();
//        System.out.println((time2 - time) /1000);
//        threadPool.shutdown();
        try {
            comlete();
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void comlete() throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> com = new CompletableFuture<>();
        new Thread(new Runnable() {
            @Override
            public void run() {
                com.complete(1);
            }
        }).start();
        System.out.println(com.get());



    }

    private static int callA(int i) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("a");
        return 0;
    }

    private static int callB(int i) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("b");

        return 0;
    }
    private static int callC(int i) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("c");

        return 0;
    }

}
